/*
 * Copyright (c) 2018-2023 北京华恒盛世科技有限公司
 * QUICKPOOL is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *     http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
*/

#ifndef TCL_INFO_H
#define TCL_INFO_H

#include "hash.h"

#define   MAXCPUS    (sptrTclRes->num_index + sptrTclRes->num_user_index)
#define   MAXMEM     (sptrTclRes->num_index + sptrTclRes->num_user_index + 1)
#define   MAXSWAP    (sptrTclRes->num_index + sptrTclRes->num_user_index + 2)
#define   MAXTMP     (sptrTclRes->num_index + sptrTclRes->num_user_index + 3)
#define   CPUFACTOR  (sptrTclRes->num_index + sptrTclRes->num_user_index + 4)

#define   HOSTTYPE   (sptrTclRes->string_start_index)
#define   HOSTMODEL  (sptrTclRes->string_start_index + 1)
#define   HOSTSTATUS (sptrTclRes->string_start_index + 2)
#define   HOSTNAME   (sptrTclRes->string_start_index + 3)

#define   SERVER     (sptrTclRes->bool_start_index)

#define   TCL_CHECK_SYNTAX  0
#define   TCL_CHECK_EXPRESSION 1

typedef enum {
    TYPE_BOOLEAN,
    TYPE_NUMERIC,
    TYPE_STRING,
} value_type_t;
enum orderType {INCR, DECR, NA};

struct resource_definition {
    char *name;
    char *des;
    value_type_t value_type;
    enum orderType order_type;
    int  flags;
    int  interval;
};

struct Tcl_Node {
    char *host_name;
    char *host_type;
    char *host_model;
    double *load;
    unsigned int max_cpu;
    double max_mem;
    double max_swp;
    double max_tmp;
    int *status;
    int server;
    char *from_type;
    char *from_model;
    int *res_bitmap;
    int *exclres_bitmap;
    HASH_TABLE_T *respair_table;
    int     ignDedicatedResource;
    int check_flag;
    int override;
};

struct Tcl_Resource {
    unsigned int num_index;
    unsigned int num_user_index;
    unsigned int num_resource;
    unsigned int string_start_index;
    unsigned int bool_start_index;
    struct resource_definition *resources;
};

extern int initialize_tcl(unsigned int, unsigned int, unsigned int, unsigned int,
                          unsigned int, struct resource_definition *);
extern void finalize_tcl(void);
extern int evaluate(char *, struct Tcl_Node *, char);
extern void freeTclInterp(void);
extern void free_tclnode(struct Tcl_Node *);

#endif
